import * as api from '../api/index.js'
export function transform13Time(timestamp, type) {
  // var date = new Date(timestamp * 1000) // 时间戳为10位需*1000，时间戳为13位的话不需乘1000
  var date = new Date(timestamp)
  var Y = date.getFullYear() + '-'
  var M = padStarta(date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'
  var D = padStarta(date.getDate())
  var h = ' ' + padStarta(date.getHours()) + ':'
  var m = padStarta(date.getMinutes()) + ':'
  var s = padStarta(date.getSeconds())
  // if (m <= 10) {
  //   m = '0' + m
  // }
  // var s = date.getSeconds()
  if (type == 0) { // 不传返回年月日
    return h + m + s
  } else if (type == 1) {
    return Y + M + D + h + m + s
  } else if (type == 2){
    return Y + M + D
  }
}
export function getDate(type,hour) {
  var date = new Date()
  var Y = date.getFullYear() + '-'
  var M = padStarta(date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'
  var D = padStarta(date.getDate())
  var h = ' ' + padStarta(date.getHours()) + ':'
  var m = padStarta(date.getMinutes()) + ':'
  var s = padStarta(date.getSeconds())
  // if (m <= 10) {
  //   m = '0' + m
  // }
  // var s = date.getSeconds()
  if (!type) { // 不传返回年月日
    return Y + M + D
  } else {
    return Y + M + D + h + m + s
  }
}
export function getTime(type, hour) {
  var date = new Date()
  var h = padStarta(date.getHours()) + ':'
  var m = padStarta(date.getMinutes())
  var s = padStarta(date.getSeconds())
  // if (m <= 10) {
  //   m = '0' + m
  // }
  // var s = date.getSeconds()
  return h + m
}
export function getHour(type, hour) {
  var date = new Date()
  var h = padStarta(date.getHours()) + ':'
  var m = padStarta(date.getMinutes()) + ':'
  var s = padStarta(date.getSeconds())
  // if (m <= 10) {
  //   m = '0' + m
  // }
  // var s = date.getSeconds()
  return h + m + s
}
function padStarta(str) {
  str = str.toString()
  str = str.padStart(2, '0')
  // console.log(str)
  return str
}
// export function getWord(word) {
//   if(word){
//     var con = '111';
//     api.getWord().then(function(res) {
//       if (res.data.code == 0) {
//         for (let i = 0; i < res.data.data.arrayList.length; i++) {
//           if (word.indexOf(res.data.data.arrayList[i].keyWord) != -1) {
//             con = word.replace(res.data.data.arrayList[i].keyWord, '***')
//           } else {
//             con = word
//           }
//         }
//       }
//     })
//     console.log(con)
//     return con;
//   }else{
//     return word
//   }
// }